package com.lagou.edu.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.lagou.edu.anno.*;

import javax.sql.DataSource;

@Configuration                                        // 配置类注解
@ComponentScan(value = {"com.lagou.edu"})             // 包扫描
@PropertySource(value = {"dataSource.properties"})    // 数据库配置文件
@EnableAutoProxy(proxyType = true)                    // 指定代理方式 默认false cglib
public class Config {

    @Value(value = "${dataSource.driver}")
    private String driverClass;
    @Value(value = "${dataSource.url}")
    private String jdbcUrl;
    @Value(value = "${dataSource.name}")
    private String username;
    @Value(value = "${dataSource.password}")
    private String password;

    @Bean
    public DataSource createDataSource(){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(driverClass);
        druidDataSource.setUrl(jdbcUrl);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
